/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package JFrame;

import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.logging.Level;
import java.util.logging.Logger;

import mooer.CtoS;
import mooer.Golbal;


/**
 * @author Evistix
 */
public class Fight_Standby extends javax.swing.JFrame {
    CtoS ctos;

    /**
     * Creates new form Card_Map
     */
    public Fight_Standby() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings( "unchecked" )
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        购买选择 = new javax.swing.ButtonGroup();
        backGround = new javax.swing.JPanel();
        返回 = new javax.swing.JButton();
        连接服务器 = new javax.swing.JButton();
        准备信息 = new javax.swing.JLabel();
        Front = new javax.swing.JPanel();
        背景 = new javax.swing.JLabel();

        setDefaultCloseOperation( javax.swing.WindowConstants.EXIT_ON_CLOSE );
        setTitle( "对战" );

        backGround.setOpaque( false );
        backGround.setPreferredSize( new java.awt.Dimension( 1000, 700 ) );
        backGround.setLayout( new org.netbeans.lib.awtextra.AbsoluteLayout() );

        返回.setText( "退出" );
        返回.addActionListener( new java.awt.event.ActionListener() {
            public void actionPerformed( java.awt.event.ActionEvent evt ) {
                返回ActionPerformed( evt );
            }
        } );
        backGround.add( 返回, new org.netbeans.lib.awtextra.AbsoluteConstraints( 410, 340, 141, 51 ) );

        连接服务器.setText( "连接服务器" );
        连接服务器.addActionListener( new java.awt.event.ActionListener() {
            public void actionPerformed( java.awt.event.ActionEvent evt ) {
                连接服务器ActionPerformed( evt );
            }
        } );
        backGround.add( 连接服务器, new org.netbeans.lib.awtextra.AbsoluteConstraints( 410, 250, 140, 50 ) );

        准备信息.setFont( new java.awt.Font( "宋体", 1, 24 ) ); // NOI18N
        backGround.add( 准备信息, new org.netbeans.lib.awtextra.AbsoluteConstraints( 400, 170, 360, 70 ) );

        Front.setOpaque( false );

        背景.setIcon( new javax.swing.ImageIcon( getClass().getResource( "/backGround/b2.png" ) ) ); // NOI18N

        javax.swing.GroupLayout FrontLayout = new javax.swing.GroupLayout( Front );
        Front.setLayout( FrontLayout );
        FrontLayout.setHorizontalGroup(
                FrontLayout.createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING )
                        .addGap( 0, 1000, Short.MAX_VALUE )
                        .addGroup( FrontLayout.createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING )
                                .addGroup( FrontLayout.createSequentialGroup()
                                        .addComponent( 背景 )
                                        .addGap( 0, 0, Short.MAX_VALUE ) ) )
                                      );
        FrontLayout.setVerticalGroup(
                FrontLayout.createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING )
                        .addGap( 0, 700, Short.MAX_VALUE )
                        .addGroup( FrontLayout.createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING )
                                .addComponent( 背景, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE ) )
                                    );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout( getContentPane() );
        getContentPane().setLayout( layout );
        layout.setHorizontalGroup(
                layout.createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING )
                        .addGroup( layout.createSequentialGroup()
                                .addComponent( backGround, javax.swing.GroupLayout.PREFERRED_SIZE, 998, javax.swing.GroupLayout.PREFERRED_SIZE )
                                .addGap( 0, 2, Short.MAX_VALUE ) )
                        .addGroup( layout.createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING )
                                .addGroup( layout.createSequentialGroup()
                                        .addComponent( Front, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE )
                                        .addGap( 0, 0, Short.MAX_VALUE ) ) )
                                 );
        layout.setVerticalGroup(
                layout.createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING )
                        .addComponent( backGround, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE )
                        .addGroup( layout.createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING )
                                .addGroup( javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                        .addGap( 0, 0, Short.MAX_VALUE )
                                        .addComponent( Front, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE ) ) )
                               );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void 返回ActionPerformed( java.awt.event.ActionEvent evt ) {//GEN-FIRST:event_返回ActionPerformed
        // TODO add your handling code here:
        this.setVisible( false );
        new Main_UI().setVisible( true );
        System.out.print( Golbal.standby );
    }//GEN-LAST:event_返回ActionPerformed

    private void 连接服务器ActionPerformed( java.awt.event.ActionEvent evt ) {//GEN-FIRST:event_连接服务器ActionPerformed
        // TODO add your handling code here:
        if( Golbal.standby == 0 ){
            ctos = new CtoS( Golbal.ip );
            ctos.send( "standby" );


//               Wait.wait_(ctos, "123");
//                this.setVisible(false);
//            new Fight(ctos).setVisible(true);

//                InputStream is;
//                try {
//                    is = ctos.sk.getInputStream();
//                    DataInputStream dis = new DataInputStream(is);
//                    String read;
//                    while((read = dis.readUTF()) != null){
//                        System.out.print(read);
//                        if(read.equals("standby")){
//                            break;
//                        }
//                        
//                    }
//                }catch (IOException ex) {
//                        //Logger.getLogger(Server.class.getName()).log(Level.SEVERE, null, ex);
//                    }
//               this.setVisible(false);
//           new Fight(ctos).setVisible(true);

        }
        else if( Golbal.standby == 1 ){
            Golbal.standby = 0;
            this.setVisible( false );
            new Fight( ctos ).setVisible( true );


        }


    }//GEN-LAST:event_连接服务器ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main( String args[] ) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try{
            for( javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels() ){
                if( "Nimbus".equals( info.getName() ) ){
                    javax.swing.UIManager.setLookAndFeel( info.getClassName() );
                    break;
                }
            }
        }catch( ClassNotFoundException ex ){
            Logger.getLogger( Fight_Standby.class.getName() ).log( Level.SEVERE, null, ex );
        }catch( InstantiationException ex ){
            Logger.getLogger( Fight_Standby.class.getName() ).log( Level.SEVERE, null, ex );
        }catch( IllegalAccessException ex ){
            Logger.getLogger( Fight_Standby.class.getName() ).log( Level.SEVERE, null, ex );
        }catch( javax.swing.UnsupportedLookAndFeelException ex ){
            Logger.getLogger( Fight_Standby.class.getName() ).log( Level.SEVERE, null, ex );
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater( new Runnable() {
            public void run() {
                new Fight_Standby().setVisible( true );
            }
        } );
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel Front;
    private javax.swing.JPanel backGround;
    public static javax.swing.JLabel 准备信息;
    private javax.swing.JLabel 背景;
    private javax.swing.ButtonGroup 购买选择;
    private javax.swing.JButton 返回;
    private javax.swing.JButton 连接服务器;
    // End of variables declaration//GEN-END:variables
}
